package com.lemon.core.oss.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 文件扩展名枚举
 *
 * @author pan
 * @since 2020-08-27
 */
@Getter
@AllArgsConstructor
public enum FileExtensionEnum {

    /**
     * bpm
     */
    BMP("bmp", "image/bmp", 1),
    GIF("gif", "image/gif", 1),
    JPEG("jpeg", "image/jpg", 1),
    JPG("jpg", "image/jpg", 1),
    PNG("png", "image/jpg", 1),
    XML("xml", "text/xml", 3),
    HTML("html", "text/html", 3),
    TXT("txt", "text/plain", 3),
    VSD("vsd", "application/vnd.visio", 3),
    PPTX("pptx", "application/vnd.ms-powerpoint", 3),
    PPT("ppt", "application/vnd.ms-powerpoint", 3),
    DOCX("docx", "application/msword", 3),
    DOC("doc", "application/msword", 3),
    OTHER("other", "application/octet-stream", 3);

    private final String ext;
    private final String contentType;
    private final Integer type;

    public static FileExtensionEnum getByExt(String ext) {
        FileExtensionEnum[] values = FileExtensionEnum.values();
        for (FileExtensionEnum value : values) {
            if (value.getExt().equalsIgnoreCase(ext)) {
                return value;
            }
        }
        return OTHER;
    }

    public static String getContentTypeByExt(String ext) {
        return getByExt(ext).getContentType();
    }

    public static Integer getTypeByExt(String ext) {
        return getByExt(ext).getType();
    }
}
